package org.jeecg.modules.depart.api;

import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.ServiceNameConstants;
import org.jeecg.modules.depart.callback.DeptApiCallback;
import org.jeecg.modules.depart.entity.SysDepart;
import org.jeecg.modules.depart.entity.SysDepartTreeModel;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Component
@FeignClient(contextId = "SysDepartApi", value = ServiceNameConstants.SERVICE_SYSTEM, path = ServiceNameConstants.PATH_SYS_DEPART, fallback = DeptApiCallback.class)
@ConditionalOnMissingClass("org.jeecg.modules.system.controller.SysDepartController")
public interface DeptApi {

    @GetMapping("/getById")
    Result<SysDepart> getById(@RequestParam String deptId);

    @PostMapping("save")
    Result<SysDepart> add(@RequestBody SysDepart sysDepart);

    @GetMapping("getTree")
    @ApiOperation(value = "根据登录用户查询部门树【包含自身】")
    Result<List<SysDepartTreeModel>> getTree(@RequestParam String userId);

    @GetMapping("getChildTree")
    @ApiOperation(value = "根据部门id查询当前部门的子部门树【不包含自身】")
    Result<List<SysDepartTreeModel>> getChildDeptTree(@RequestParam String deptId);

    @GetMapping("getChildIdList")
    @ApiOperation(value = "通过部门ID查询所有子部门")
    Result<List<String>> getChildIdList(@RequestParam String deptId);

    @PutMapping(value = "/edit")
    Result<SysDepart> edit(@RequestBody SysDepart depart);

    @GetMapping(value = "getSubjectOfCostCalc")
    @ApiOperation(value = "根据部门查询部门下的核算账户")
    Result<List<SysDepart>> getSubjectOfCostCalc(@RequestParam String deptId,@RequestParam(required = false) String name);

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除部门")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id);


    @GetMapping("getList")
    @ApiOperation(value = "根据登录用户查询部门集合【包含自身】")
    Result<List<SysDepart>> getList(@RequestParam String userId);
}
